dotnet core ef add multiple records

74

dotnet core ef add multiple records -

 
using (EFCoreContext db = new EFCoreContext())
{
    List<Department> deps = new List<Department>();
 
    deps.Add(new Department { Name = "Dept1", Descr = "" });
    deps.Add(new Department { Name = "Dept2", Descr = "" });
 
    db.Departments.AddRange(deps);
    db.SaveChanges();
}
 
//SQL Command
INSERT INTO [Departments] ([Descr], [Name])
VALUES (@p0, @p1);
 
SELECT [DepartmentID]
FROM [Departments]
WHERE @@ROWCOUNT = 1 AND [DepartmentID] = scope_identity();
          
INSERT INTO [Departments] ([Descr], [Name])
VALUES (@p0, @p1);
         
SELECT [DepartmentID]
FROM [Departments]
WHERE @@ROWCOUNT = 1 AND [DepartmentID] = scope_identity();
 

Comments

Submit
0 Comments